import { Component, Input, OnInit } from '@angular/core';
import { GitConfig ,GenYaml} from '@api/git';
import { CreateService } from '@common/services/create/service';
import { GitManagerService } from '@common/services/git/gitmanager';
import { error } from 'console';

@Component({
  selector: 'kd-k8s-config-yaml',
  templateUrl: './k8s-config-yaml.component.html',
  styleUrls: ['./k8s-config-yaml.component.scss']
})
export class K8sConfigYamlComponent implements OnInit {

  constructor(private readonly git_: GitManagerService,
    private readonly create_: CreateService) { }
  options = {
    theme: 'vs',
    readOnly : false ,
    language: 'yaml'
  };
  code = "hello world"
  gitinfo:GitConfig
  upload_active = true

  @Input("gitconfig")
  set gitconfig(giti : GitConfig) {
    this.gitinfo = giti
  }
  
  
  ngOnInit(): void {
  }

  autogen():void  {
    let  genyaml:GenYaml = {
      gitid : this.gitinfo.id,
      gencode: '',
      genmode : 3 , 
    }
    this.git_.SubModuleAutoGenK8sYaml(genyaml).subscribe(
      data => this.code=data.gencode
    )
  }

  create(): void {
    this.upload_active= false 
    this.create_.createContent(this.code).then(() => {
      this.upload_active = true
    }).catch(
      err=> {
        this.upload_active = true
        console.log(err)  
      }
    )

    ;
  }
  isCreateDisabled():boolean{
    return this.upload_active 
  }
}
